/*
 * VideoEditor.java
 *
 * Created on 16-mar-2009, 20:24:09
 */

package grupb.upf.gui;

import grupb.upf.XMLObjects.Tag;
import grupb.upf.XMLObjects.Tagging;
import grupb.upf.XMLObjects.Video;
import grupb.upf.XMLObjects.impl.PersonalTag;
import grupb.upf.XMLObjects.impl.PredefinedTag;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Collections;
import java.util.List;
import java.util.Vector;
import javax.swing.DefaultListModel;
import javax.swing.JFileChooser;
import javax.swing.filechooser.FileFilter;
import javax.swing.filechooser.FileSystemView;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * <p>This class contains the video edition.</p>
 *
 * @version    0.0.1-SNAPSHOT
 * @author Group B
 */
public class VideoEditor extends javax.swing.JPanel {
    /**
     * The logger. A new logger <code>grupb.upf.gui.VideoEditor</code>
     * is created to add the logs of this VideoEditor
     */
    private static final Log LOG = LogFactory.getLog(VideoEditor.class);
    /**
     * The file.
     */
    private File file;
    /**
     * The principal GUI.
     */
    private P2Piki p2piki;
    /**
     * The video that we are editing.
     */
    private Video video;
    /**
     * The list of tags.
     */
    private List < Tag > auxTagsList = new Vector();
    /**
     * The default list model of edited tags.
     */
    private DefaultListModel editedTagsModel = new DefaultListModel();
    /**
     * The type of videos format accepted.
     */
    private static final String [] VIDEO_FORMATS =
    {"avi", "mpeg", "mpg", "asf", "wmv", "wma", "ogg", "wav", "flv"};
    /**
     * The list of Taxonomies.
     */
    private List taxonomies;

    /** Creates new form VideoEditor */
    public VideoEditor(final P2Piki p2p) {
        this.p2piki = p2p;
        initComponents();
    }

    /**
     * Method to set up the categories of the ontologies, we receive it from
     * the main class.
     * @param t the complete t
     */
    public void initCategories(final List t) {
        taxonomies = t;
        List tax;
        categoriesComboBox.removeAllItems();
        categoriesComboBox.addItem("Choose a category");
        for (int i = 0; i < t.size(); i++) {
            tax = (List) t.get(i);
            categoriesComboBox.addItem((String) tax.get(0));
        }
    }

    /**
     * Method to set a video into this panel.
     * @param f the video
     */
    public void setVideo(final File f) {
        this.file = f.getAbsoluteFile();
        getProperties();
    }

    /**
     * Method to get the properties and show them.
     */
    private void getProperties() {
        String path = file.getAbsolutePath().replaceAll("\\\\", "/");
        int index = path.indexOf(grupb.upf.util.Config.getProperty(
                "video.folder")) +
                grupb.upf.util.Config.getProperty("video.folder").length();
        if (index != -1) {
            urlTextField.setText(file.getAbsolutePath());
        }
        path = path.substring(index);
        video = p2piki.getVideo(path);
        if (video != null) {
            titleView.setText(video.getMetadataDC()
                    .getContentProperty("dc.title"));
            dateView.setText(getDate(video.getMetadataDC()
                    .getInstantiationProperty("dc.date")));
            title.setText(video.getMetadataDC()
                    .getContentProperty("dc.title"));
            subject.setText(video.getMetadataDC()
                    .getContentProperty("dc.subject"));
            description.setText(video.getMetadataDC()
                    .getContentProperty("dc.description"));
            source.setText(video.getMetadataDC()
                    .getContentProperty("dc.source"));
            creator.setText(video.getMetadataDC()
                    .getIntellectualProperty("dc.creator"));
            publisher.setText(video.getMetadataDC()
                    .getIntellectualProperty("dc.publisher"));
            contributor.setText(video.getMetadataDC()
                    .getIntellectualProperty("dc.contributor"));
            rights.setText(video.getMetadataDC()
                    .getIntellectualProperty("dc.rights"));
            Tagging tags = video.getTags();
            List<Tag> listOfTags = tags.getPersonalTags();
            auxTagsList = new Vector();
            editedTagsModel.removeAllElements();
            for (int i = 0; i < listOfTags.size(); i++) {
                auxTagsList.add(listOfTags.get(i));
                editedTagsModel.addElement(
                        (String) listOfTags.get(i).getTag());
            }
            listOfTags = tags.getPredefinedTags();
            for (int i = 0; i < listOfTags.size(); i++) {
                auxTagsList.add(listOfTags.get(i));
                editedTagsModel.addElement(
                        (String) listOfTags.get(i).getTag());
            }
        } else {
            if (LOG.isInfoEnabled()) {
                final StringBuffer sb = new StringBuffer(
                        "The image isn't in the database: ")
                        .append(path);
                LOG.info(sb);
            }
            video = new grupb.upf.XMLObjects.impl.Video();
            video.setMetadataDC(new grupb.upf.XMLObjects.impl.MetadataDC());
            Tagging tags = new grupb.upf.XMLObjects.impl.Tagging();
            tags.setPersonalTags(new Vector());
            tags.setPredefinedTags(new Vector());
            video.setTags(tags);
            video.setID(-1);
            titleView.setText("");
            dateView.setText("");
            title.setText("");
            subject.setText("");
            description.setText("");
            source.setText("");
            creator.setText("");
            publisher.setText("");
            contributor.setText("");
            rights.setText("");
            auxTagsList = new Vector();
            editedTagsModel.removeAllElements();
            p2piki.addWarning("This video isn't stored in the database,\nthe changes about tags and the metadata of the video \naren't going to be saved if you don't save it in the P2Piki's folder.");
        }
    }

    /**
     * Method to delete a video from the DB and physically.
     */
    public boolean deleteVideo() {
        //La guardo y así me aseguro que los streams y tal están cerrados.
        boolean deleted = false;
        for (int i = 0; i < 100 && !deleted; i++) {
            if(file.delete()) {
                deleted = true;
            }
        }
        if (deleted) {
            if (video != null && video.getID() != -1) {
                final boolean flag = p2piki.deleteVideo(video.getID());
                if (flag) {
                    if (LOG.isInfoEnabled()) {
                        LOG.info("Video deleted correctly.");
                    }
                    p2piki.addInfo("Video deleted correctly.");
                } else {
                    if (LOG.isErrorEnabled()) {
                        LOG.error("Error deleting the video from the DB.");
                    }
                    p2piki.addError("Error deleting the video from the DB.");
                }
            } else {
                if (LOG.isInfoEnabled()) {
                    LOG.info("The video isnt't in the database");
                }
            }
        } else {
            if (LOG.isErrorEnabled()) {
                LOG.error("Error deleting the video, maybe it is being used by another application.");
                }
            p2piki.addError("Error deleting the video,\nmaybe it is being used by another application.");
        }
        return deleted;
    }
    /**
     * Method to update the properties of a video.
     */
    public void updateProperties() {
        updateVideoProperties();
        String path = urlTextField.getText().trim();
        int index = path.replaceAll("\\\\", "/").indexOf(grupb.upf.util.Config.getProperty(
                "video.folder")) +
                grupb.upf.util.Config.getProperty("video.folder").length();
        if (video != null) {
            titleView.setText(video.getMetadataDC()
                    .getContentProperty("dc.title"));
            if (video.getMetadataDC()
                    .getInstantiationProperty("dc.date") != null) {
                dateView.setText(getDate(video.getMetadataDC()
                    .getInstantiationProperty("dc.date")));
            }
            boolean flag = false;
            if (index != (-1 + grupb.upf.util.Config.getProperty(
                    "video.folder").length())) {
                if (!path.equalsIgnoreCase(file.getAbsolutePath())) {
                    //different path
                    copy(file, new File(urlTextField.getText().trim()
                            .replaceAll("\\\\", "/")));
                    path = path.substring(index).replaceAll("\\\\", "/");
                    video.setURL(path);
                    flag = p2piki.addVideo(video);
                    if (flag) {
                        p2piki.addInfo("Video added correctly.");
                    } else {
                        p2piki.addError("Error added the video.");
                    }
                } else {
                    path = path.substring(index).replaceAll("\\\\", "/");
                    video.setURL(path);
                    if (video.getID() != -1) {
                        flag = p2piki.updateVideo(video);
                        if (flag) {
                            p2piki.addInfo("Video updated correctly.");
                        } else {
                            p2piki.addError("Error updating the video.");
                        }
                    } else {
                        flag = p2piki.addVideo(video);
                        if (flag) {
                            p2piki.addInfo("Video added correctly.");
                        } else {
                            p2piki.addError("Error added the video.");
                        }
                    }
                }
            } else {
                p2piki.addError("The new URL is outside of the P2Piki's folder, changes hasn't been saved.");
            }
        } else {
            p2piki.addError("Error, it was impossible to update the properties because it isn't in the Database.");
        }
    }
    /**
     * Method to update the video properties.
     */
    private void updateVideoProperties() {
        video.getMetadataDC().setContentProperty("dc.title", title.getText()
                .trim());
        video.getMetadataDC().setContentProperty("dc.subject", subject
                .getText().trim());
        video.getMetadataDC().setContentProperty("dc.description", description
                .getText().trim());
        video.getMetadataDC().setContentProperty("dc.source", source.getText()
                .trim());
        video.getMetadataDC().setIntellectualProperty("dc.creator", creator
                .getText().trim());
        video.getMetadataDC().setIntellectualProperty("dc.publisher", publisher
                .getText().trim());
        video.getMetadataDC().setIntellectualProperty("dc.contributor",
                contributor.getText().trim());
        video.getMetadataDC().setIntellectualProperty("dc.rights", rights
                .getText().trim());
        final List predefinedTags = new Vector();
        final List personalTags = new Vector();
        for (int i = 0; i < auxTagsList.size(); i++) {
            if (auxTagsList.get(i) instanceof PredefinedTag) {
                predefinedTags.add(auxTagsList.get(i));
            } else if (auxTagsList.get(i) instanceof PersonalTag) {
                personalTags.add(auxTagsList.get(i));
            }
        }
        video.getTags().setPredefinedTags(predefinedTags);
        video.getTags().setPersonalTags(personalTags);
    }
    /**
     * Method to copy a file
     * @param src the source
     * @param dst the destination
     * @throws IOException the exception
     */
    public static void copy(File src, File dst) {
        InputStream in = null;
        try {
            in = new FileInputStream(src);
            OutputStream out = new FileOutputStream(dst);
            byte[] buf = new byte[1024];
            int len;
            while ((len = in.read(buf)) > 0) {
                out.write(buf, 0, len);
            }
            in.close();
            out.close();
        } catch (IOException ex) {
            LOG.fatal("Fatal error trying to copy a file.", ex);
        } finally {
            try {
                in.close();
            } catch (IOException ex) {
            LOG.fatal("Fatal error trying to copy a file.", ex);
            }
        }
    }

    /**
     * Method to get the date from an existent String date.
     * @param date the date in String format (YYYYMMDD)
     * @return the date formatted to (DD-MM-YYYY)
     */
    private String getDate(final String date) {
        String newDate = "(" + date.substring(6, 8) + "/" +
                date.substring(4, 6) + "/" + date.substring(0, 4) + ")";
        return newDate;
    }

    /**
     * Method to update the view.
     */
    private void update() {
        p2piki.repaint();
    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        ontologiesPopupMenu = new javax.swing.JPopupMenu();
        desktopPane = new javax.swing.JDesktopPane();
        deleteInternalFrame = new javax.swing.JInternalFrame();
        deleteYesButton = new javax.swing.JButton();
        deleteNoButton = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        editionPanelContainer = new javax.swing.JPanel();
        editionPanel = new javax.swing.JPanel();
        deleteButton = new javax.swing.JButton();
        titleView = new javax.swing.JLabel();
        dateView = new javax.swing.JLabel();
        openVideoButton = new javax.swing.JButton();
        openVideoButton1 = new javax.swing.JButton();
        updatePropertiesButton = new javax.swing.JButton();
        resetPropertiesButton = new javax.swing.JButton();
        intellectualpanel = new javax.swing.JPanel();
        creatorLabel = new javax.swing.JLabel();
        publisherLabel = new javax.swing.JLabel();
        publisher = new javax.swing.JTextField();
        creator = new javax.swing.JTextField();
        contributorLabel = new javax.swing.JLabel();
        contributor = new javax.swing.JTextField();
        rights = new javax.swing.JTextField();
        rightsLabel = new javax.swing.JLabel();
        generalPanel = new javax.swing.JPanel();
        titleLabel = new javax.swing.JLabel();
        title = new javax.swing.JTextField();
        subjectLabel = new javax.swing.JLabel();
        subject = new javax.swing.JTextField();
        descriptionLabel = new javax.swing.JLabel();
        source = new javax.swing.JTextField();
        sourceLabel = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        description = new javax.swing.JTextArea();
        jPanel1 = new javax.swing.JPanel();
        addTagTabbedPane1 = new javax.swing.JTabbedPane();
        personalTagPanel1 = new javax.swing.JPanel();
        addTagTextField = new javax.swing.JTextField();
        addPersonalTagButton = new javax.swing.JButton();
        ontologyTagPanel1 = new javax.swing.JPanel();
        addOntologyTagButton = new javax.swing.JButton();
        addOntologyTagTextField = new javax.swing.JTextField();
        categoryLabel1 = new javax.swing.JLabel();
        categoriesComboBox = new javax.swing.JComboBox();
        editedTagsScrollPane1 = new javax.swing.JScrollPane();
        editedTagsList = new javax.swing.JList();
        deleteTagButton = new javax.swing.JButton();
        urlTextField = new javax.swing.JTextField();
        titleLabel1 = new javax.swing.JLabel();
        videoUrlBrowseButton = new javax.swing.JButton();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();

        ontologiesPopupMenu.setAutoscrolls(true);
        ontologiesPopupMenu.setMaximumSize(new java.awt.Dimension(260, 100));

        desktopPane.setMaximumSize(new java.awt.Dimension(546, 556));
        desktopPane.setMinimumSize(new java.awt.Dimension(546, 556));

        deleteInternalFrame.setTitle("Delete a video");
        deleteInternalFrame.setFrameIcon(new javax.swing.ImageIcon(getClass().getResource("/graphics/p2pikiLogo.png"))); // NOI18N
        deleteInternalFrame.setMaximumSize(new java.awt.Dimension(200, 114));
        deleteInternalFrame.setMinimumSize(new java.awt.Dimension(200, 114));

        deleteYesButton.setText("Yes");
        deleteYesButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteYesButtonActionPerformed(evt);
            }
        });

        deleteNoButton.setText("No");
        deleteNoButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteNoButtonActionPerformed(evt);
            }
        });

        jLabel3.setText("Are you sure to delete this video?");

        javax.swing.GroupLayout deleteInternalFrameLayout = new javax.swing.GroupLayout(deleteInternalFrame.getContentPane());
        deleteInternalFrame.getContentPane().setLayout(deleteInternalFrameLayout);
        deleteInternalFrameLayout.setHorizontalGroup(
            deleteInternalFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(deleteInternalFrameLayout.createSequentialGroup()
                .addGroup(deleteInternalFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(deleteInternalFrameLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel3))
                    .addGroup(deleteInternalFrameLayout.createSequentialGroup()
                        .addGap(38, 38, 38)
                        .addComponent(deleteYesButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(deleteNoButton)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        deleteInternalFrameLayout.setVerticalGroup(
            deleteInternalFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, deleteInternalFrameLayout.createSequentialGroup()
                .addContainerGap(24, Short.MAX_VALUE)
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(deleteInternalFrameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(deleteYesButton)
                    .addComponent(deleteNoButton))
                .addContainerGap())
        );

        deleteInternalFrame.setBounds(50, 50, 190, 110);
        desktopPane.add(deleteInternalFrame, javax.swing.JLayeredPane.POPUP_LAYER);

        editionPanelContainer.setBackground(new java.awt.Color(255, 255, 255));
        editionPanelContainer.setMaximumSize(new java.awt.Dimension(550, 567));
        editionPanelContainer.setPreferredSize(new java.awt.Dimension(550, 567));

        editionPanel.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(102, 102, 102)));
        editionPanel.setMaximumSize(new java.awt.Dimension(541, 307));
        editionPanel.setMinimumSize(new java.awt.Dimension(541, 307));

        deleteButton.setBackground(new java.awt.Color(255, 255, 255));
        deleteButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/graphics/Delete2.png"))); // NOI18N
        deleteButton.setToolTipText("Delete");
        deleteButton.setBorderPainted(false);
        deleteButton.setFocusPainted(false);
        deleteButton.setMaximumSize(new java.awt.Dimension(24, 18));
        deleteButton.setMinimumSize(new java.awt.Dimension(24, 18));
        deleteButton.setPreferredSize(new java.awt.Dimension(24, 18));
        deleteButton.setPressedIcon(new javax.swing.ImageIcon(getClass().getResource("/graphics/Delete2Pressed.png"))); // NOI18N
        deleteButton.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/graphics/Delete2Rollover.png"))); // NOI18N
        deleteButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteButtonActionPerformed(evt);
            }
        });

        titleView.setFont(new java.awt.Font("Verdana", 1, 12));
        titleView.setText("Title");

        dateView.setText("(02 - 06 - 2008)");

        openVideoButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/graphics/openVideo.png"))); // NOI18N
        openVideoButton.setToolTipText("Open video");
        openVideoButton.setActionCommand("Open video");
        openVideoButton.setBorderPainted(false);
        openVideoButton.setFocusPainted(false);
        openVideoButton.setMaximumSize(new java.awt.Dimension(52, 46));
        openVideoButton.setMinimumSize(new java.awt.Dimension(52, 46));
        openVideoButton.setPreferredSize(new java.awt.Dimension(52, 46));
        openVideoButton.setPressedIcon(new javax.swing.ImageIcon(getClass().getResource("/graphics/openVideoPressed.png"))); // NOI18N
        openVideoButton.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/graphics/openVideoRollover.png"))); // NOI18N
        openVideoButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                openVideoButtonActionPerformed(evt);
            }
        });

        openVideoButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/graphics/addVideo.png"))); // NOI18N
        openVideoButton1.setToolTipText("Import video");
        openVideoButton1.setBorderPainted(false);
        openVideoButton1.setFocusPainted(false);
        openVideoButton1.setMaximumSize(new java.awt.Dimension(52, 46));
        openVideoButton1.setMinimumSize(new java.awt.Dimension(52, 46));
        openVideoButton1.setPreferredSize(new java.awt.Dimension(52, 46));
        openVideoButton1.setPressedIcon(new javax.swing.ImageIcon(getClass().getResource("/graphics/addVideoPressed.png"))); // NOI18N
        openVideoButton1.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/graphics/addVideoRollover.png"))); // NOI18N
        openVideoButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                openVideoButton1ActionPerformed(evt);
            }
        });

        updatePropertiesButton.setText("Save changes");
        updatePropertiesButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                updatePropertiesButtonActionPerformed(evt);
            }
        });

        resetPropertiesButton.setText("Reset");
        resetPropertiesButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                resetPropertiesButtonActionPerformed(evt);
            }
        });

        intellectualpanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Intellectual Properties", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11))); // NOI18N

        creatorLabel.setText("Creator");

        publisherLabel.setText("Publisher");

        contributorLabel.setText("Contributor");

        rightsLabel.setText("Rights");

        javax.swing.GroupLayout intellectualpanelLayout = new javax.swing.GroupLayout(intellectualpanel);
        intellectualpanel.setLayout(intellectualpanelLayout);
        intellectualpanelLayout.setHorizontalGroup(
            intellectualpanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(intellectualpanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(intellectualpanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(publisherLabel)
                    .addComponent(creatorLabel))
                .addGap(31, 31, 31)
                .addGroup(intellectualpanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(publisher)
                    .addComponent(creator, javax.swing.GroupLayout.DEFAULT_SIZE, 125, Short.MAX_VALUE))
                .addGap(39, 39, 39)
                .addGroup(intellectualpanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(contributorLabel)
                    .addComponent(rightsLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 14, Short.MAX_VALUE)
                .addGroup(intellectualpanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(rights)
                    .addComponent(contributor, javax.swing.GroupLayout.DEFAULT_SIZE, 200, Short.MAX_VALUE))
                .addContainerGap())
        );
        intellectualpanelLayout.setVerticalGroup(
            intellectualpanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(intellectualpanelLayout.createSequentialGroup()
                .addGroup(intellectualpanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(creatorLabel)
                    .addComponent(creator, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(contributor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(contributorLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(intellectualpanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(publisherLabel)
                    .addComponent(publisher, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(rightsLabel)
                    .addComponent(rights, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );

        generalPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "General", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11))); // NOI18N

        titleLabel.setText("Title");

        subjectLabel.setText("Subject");

        descriptionLabel.setText("Description");

        sourceLabel.setText("Source");

        description.setColumns(20);
        description.setRows(5);
        jScrollPane1.setViewportView(description);

        javax.swing.GroupLayout generalPanelLayout = new javax.swing.GroupLayout(generalPanel);
        generalPanel.setLayout(generalPanelLayout);
        generalPanelLayout.setHorizontalGroup(
            generalPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(generalPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(generalPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(generalPanelLayout.createSequentialGroup()
                        .addGroup(generalPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(subjectLabel)
                            .addComponent(titleLabel))
                        .addGroup(generalPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(generalPanelLayout.createSequentialGroup()
                                .addGap(37, 37, 37)
                                .addComponent(title))
                            .addGroup(generalPanelLayout.createSequentialGroup()
                                .addGap(38, 38, 38)
                                .addGroup(generalPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(source)
                                    .addComponent(subject, javax.swing.GroupLayout.DEFAULT_SIZE, 122, Short.MAX_VALUE))))
                        .addGap(14, 14, 14)
                        .addComponent(descriptionLabel))
                    .addComponent(sourceLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 240, Short.MAX_VALUE)
                .addContainerGap())
        );
        generalPanelLayout.setVerticalGroup(
            generalPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(generalPanelLayout.createSequentialGroup()
                .addGroup(generalPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(title, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(titleLabel)
                    .addComponent(descriptionLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(generalPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(subject, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(subjectLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(generalPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(sourceLabel)
                    .addComponent(source, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Tags edition", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11))); // NOI18N

        addTagTabbedPane1.setMaximumSize(new java.awt.Dimension(211, 180));
        addTagTabbedPane1.setMinimumSize(new java.awt.Dimension(211, 180));

        personalTagPanel1.setBackground(new java.awt.Color(255, 255, 255));
        personalTagPanel1.setMaximumSize(new java.awt.Dimension(209, 152));
        personalTagPanel1.setMinimumSize(new java.awt.Dimension(209, 152));

        addPersonalTagButton.setText("Add Tag");
        addPersonalTagButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addPersonalTagButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout personalTagPanel1Layout = new javax.swing.GroupLayout(personalTagPanel1);
        personalTagPanel1.setLayout(personalTagPanel1Layout);
        personalTagPanel1Layout.setHorizontalGroup(
            personalTagPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(personalTagPanel1Layout.createSequentialGroup()
                .addGroup(personalTagPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(personalTagPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(addTagTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 186, Short.MAX_VALUE))
                    .addGroup(personalTagPanel1Layout.createSequentialGroup()
                        .addGap(59, 59, 59)
                        .addComponent(addPersonalTagButton, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        personalTagPanel1Layout.setVerticalGroup(
            personalTagPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(personalTagPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(addTagTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(35, 35, 35)
                .addComponent(addPersonalTagButton)
                .addContainerGap(19, Short.MAX_VALUE))
        );

        addTagTabbedPane1.addTab("Personal Tag", personalTagPanel1);

        ontologyTagPanel1.setBackground(new java.awt.Color(255, 255, 255));
        ontologyTagPanel1.setMaximumSize(new java.awt.Dimension(209, 152));
        ontologyTagPanel1.setMinimumSize(new java.awt.Dimension(209, 152));

        addOntologyTagButton.setText("Add Tag");
        addOntologyTagButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addOntologyTagButtonActionPerformed(evt);
            }
        });

        addOntologyTagTextField.setEnabled(false);
        addOntologyTagTextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                addOntologyTagTextFieldKeyReleased(evt);
            }
        });

        categoryLabel1.setText("Category");

        categoriesComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Choose a category" }));
        categoriesComboBox.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                categoriesComboBoxItemStateChanged(evt);
            }
        });

        javax.swing.GroupLayout ontologyTagPanel1Layout = new javax.swing.GroupLayout(ontologyTagPanel1);
        ontologyTagPanel1.setLayout(ontologyTagPanel1Layout);
        ontologyTagPanel1Layout.setHorizontalGroup(
            ontologyTagPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(ontologyTagPanel1Layout.createSequentialGroup()
                .addGroup(ontologyTagPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, ontologyTagPanel1Layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(addOntologyTagTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 186, Short.MAX_VALUE))
                    .addGroup(ontologyTagPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(categoryLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 15, Short.MAX_VALUE)
                        .addComponent(categoriesComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(ontologyTagPanel1Layout.createSequentialGroup()
                        .addGap(58, 58, 58)
                        .addComponent(addOntologyTagButton, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        ontologyTagPanel1Layout.setVerticalGroup(
            ontologyTagPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, ontologyTagPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(addOntologyTagTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(ontologyTagPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(categoryLabel1)
                    .addComponent(categoriesComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(addOntologyTagButton)
                .addGap(129, 129, 129))
        );

        addTagTabbedPane1.addTab("Ontology Tag", ontologyTagPanel1);

        editedTagsScrollPane1.setMaximumSize(new java.awt.Dimension(144, 130));
        editedTagsScrollPane1.setMinimumSize(new java.awt.Dimension(144, 130));
        editedTagsScrollPane1.setPreferredSize(new java.awt.Dimension(144, 130));

        editedTagsList.setModel(editedTagsModel);
        editedTagsList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        editedTagsList.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                editedTagsListValueChanged(evt);
            }
        });
        editedTagsList.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                editedTagsListFocusLost(evt);
            }
        });
        editedTagsScrollPane1.setViewportView(editedTagsList);

        deleteTagButton.setText("Delete Tag");
        deleteTagButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteTagButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(80, 80, 80)
                .addComponent(addTagTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 211, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(6, 6, 6)
                        .addComponent(editedTagsScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(31, 31, 31)
                        .addComponent(deleteTagButton, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(86, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(addTagTabbedPane1, javax.swing.GroupLayout.Alignment.LEADING, 0, 0, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                        .addComponent(editedTagsScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(deleteTagButton)))
                .addGap(20, 20, 20))
        );

        urlTextField.setEditable(false);
        urlTextField.setFocusable(false);

        titleLabel1.setText("URL");

        videoUrlBrowseButton.setFont(new java.awt.Font("Tahoma", 0, 10));
        videoUrlBrowseButton.setText("Browse");
        videoUrlBrowseButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                videoUrlBrowseButtonActionPerformed(evt);
            }
        });

        jLabel6.setFont(new java.awt.Font("Tahoma", 2, 11));
        jLabel6.setText("The URL into P2Piki.");

        jLabel7.setFont(new java.awt.Font("Tahoma", 2, 11));
        jLabel7.setText("It has to be in the project to be added to the DB.");

        jButton1.setFont(new java.awt.Font("Verdana", 1, 14));
        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/graphics/playVideo.png"))); // NOI18N
        jButton1.setText("View Video");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout editionPanelLayout = new javax.swing.GroupLayout(editionPanel);
        editionPanel.setLayout(editionPanelLayout);
        editionPanelLayout.setHorizontalGroup(
            editionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(generalPanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(intellectualpanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(editionPanelLayout.createSequentialGroup()
                .addGap(18, 18, 18)
                .addGroup(editionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel7)
                    .addGroup(editionPanelLayout.createSequentialGroup()
                        .addGroup(editionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(editionPanelLayout.createSequentialGroup()
                                .addComponent(titleView)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(dateView)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(deleteButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(editionPanelLayout.createSequentialGroup()
                                .addComponent(titleLabel1)
                                .addGap(37, 37, 37)
                                .addComponent(urlTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 151, Short.MAX_VALUE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(videoUrlBrowseButton)))
                        .addGap(6, 6, 6))
                    .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(39, 39, 39)
                .addGroup(editionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(editionPanelLayout.createSequentialGroup()
                        .addComponent(openVideoButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(openVideoButton1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 184, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, editionPanelLayout.createSequentialGroup()
                .addContainerGap(165, Short.MAX_VALUE)
                .addComponent(updatePropertiesButton)
                .addGap(18, 18, 18)
                .addComponent(resetPropertiesButton, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(163, 163, 163))
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        editionPanelLayout.setVerticalGroup(
            editionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(editionPanelLayout.createSequentialGroup()
                .addGroup(editionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(editionPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(editionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(deleteButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(editionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(titleView)
                                .addComponent(dateView)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(editionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(urlTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(titleLabel1)
                            .addComponent(videoUrlBrowseButton, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(openVideoButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(openVideoButton1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(editionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(editionPanelLayout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 33, Short.MAX_VALUE)
                        .addComponent(jLabel7))
                    .addGroup(editionPanelLayout.createSequentialGroup()
                        .addGap(14, 14, 14)
                        .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(generalPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(intellectualpanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(8, 8, 8)
                .addGroup(editionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(resetPropertiesButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(updatePropertiesButton, javax.swing.GroupLayout.DEFAULT_SIZE, 31, Short.MAX_VALUE))
                .addContainerGap())
        );

        javax.swing.GroupLayout editionPanelContainerLayout = new javax.swing.GroupLayout(editionPanelContainer);
        editionPanelContainer.setLayout(editionPanelContainerLayout);
        editionPanelContainerLayout.setHorizontalGroup(
            editionPanelContainerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(editionPanelContainerLayout.createSequentialGroup()
                .addComponent(editionPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        editionPanelContainerLayout.setVerticalGroup(
            editionPanelContainerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(editionPanelContainerLayout.createSequentialGroup()
                .addComponent(editionPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        editionPanelContainer.setBounds(0, 0, 550, 560);
        desktopPane.add(editionPanelContainer, javax.swing.JLayeredPane.DEFAULT_LAYER);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(desktopPane, javax.swing.GroupLayout.DEFAULT_SIZE, 546, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(desktopPane, javax.swing.GroupLayout.DEFAULT_SIZE, 600, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents

    private void deleteYesButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteYesButtonActionPerformed
        // TODO add your handling code here:
        deleteInternalFrame.setVisible(false);
        File parent = file.getParentFile();
        if (deleteVideo()) {
            p2piki.updateTreeExplorer(1);
            p2piki.directorySelected(1, parent);
            p2piki.showListExplorer(1);
        }
}//GEN-LAST:event_deleteYesButtonActionPerformed

    private void deleteNoButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteNoButtonActionPerformed
        // TODO add your handling code here:
        deleteInternalFrame.setVisible(false);
}//GEN-LAST:event_deleteNoButtonActionPerformed

    private void deleteButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteButtonActionPerformed
        // TODO add your handling code here:
        deleteInternalFrame.setVisible(true);
        deleteInternalFrame.setLocation(50, 50);
        update();
}//GEN-LAST:event_deleteButtonActionPerformed

    private void updatePropertiesButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_updatePropertiesButtonActionPerformed
        // TODO add your handling code here:
        updateProperties();
}//GEN-LAST:event_updatePropertiesButtonActionPerformed

    private void resetPropertiesButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_resetPropertiesButtonActionPerformed
        // TODO add your handling code here:
        getProperties();
}//GEN-LAST:event_resetPropertiesButtonActionPerformed

    private void openVideoButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openVideoButton1ActionPerformed
        // TODO add your handling code here:
        JFileChooser fc = new JFileChooser();
        fc.setFileSelectionMode(javax.swing.JFileChooser.FILES_ONLY);
        if (fc.showOpenDialog(desktopPane) == JFileChooser.APPROVE_OPTION) {
            final String path = fc.getSelectedFile().getAbsolutePath();
            boolean isVideo = false;
            //format
            final String extension =
                    path.substring(path.lastIndexOf(".") + 1);
            for (int i = 0; i < VIDEO_FORMATS.length; i++) {
                if (VIDEO_FORMATS[i].equalsIgnoreCase(extension)) {
                    isVideo = true;
                }
            }
            if (isVideo) {
                setVideo(fc.getSelectedFile());
            } else {
                p2piki.addError("It isn't an accepted format.");
            }
        }
}//GEN-LAST:event_openVideoButton1ActionPerformed

    private void openVideoButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openVideoButtonActionPerformed
        // TODO add your handling code here:
        FileSystemView fsv = new FileChooser(
                new File(grupb.upf.util.Config.getProperty("video.folder"))
                .getAbsoluteFile());
        JFileChooser fc = new JFileChooser(fsv);
        fc.setCurrentDirectory(file.getParentFile());
        fc.setFileSelectionMode(javax.swing.JFileChooser.FILES_ONLY);
        if (fc.showOpenDialog(desktopPane) == JFileChooser.APPROVE_OPTION) {
            final String path = fc.getSelectedFile().getAbsolutePath();
            boolean isVideo = false;
            //format
            final String extension =
                    path.substring(path.lastIndexOf(".") + 1);
            for (int i = 0; i < VIDEO_FORMATS.length; i++) {
                if (VIDEO_FORMATS[i].equalsIgnoreCase(extension)) {
                    isVideo = true;
                }
            }
            if (isVideo) {
                setVideo(fc.getSelectedFile());
            } else {
                p2piki.addError("It isn't an accepted format.");
            }
        }
}//GEN-LAST:event_openVideoButtonActionPerformed

    private void addPersonalTagButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addPersonalTagButtonActionPerformed
        // TODO add your handling code here:
        if (addTagTextField.getText().trim().length() == 0) {
            p2piki.addError("You can't add a void tag.");
        } else {
            Tag tag = new PersonalTag();
            tag.setTag(addTagTextField.getText().trim());
            addTagTextField.setText("");
            auxTagsList.add(tag);
            editedTagsModel.addElement(tag.getTag());
        }
}//GEN-LAST:event_addPersonalTagButtonActionPerformed

    private void addOntologyTagButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addOntologyTagButtonActionPerformed
        // TODO add your handling code here:
        if (addOntologyTagTextField.getText().trim().length() == 0
                || !addOntologyTagTextField.isEnabled()) {
            p2piki.addError("You can't add a void tag or without a category.");
        } else {
            String keyword = addOntologyTagTextField.getText().trim();
            boolean keywordExists = false;
            List taxonomy;
            for (int i = 0; i < taxonomies.size(); i++) {
                taxonomy = (List) taxonomies.get(i);
                for (int j = 0; j < taxonomy.size(); j++) {
                    if (((String) taxonomy.get(j)).equals(keyword)) {
                        keywordExists = true;
                    }
                }
            }
            if (!keywordExists) {
                p2piki.addError("The Tag doesn't exist in the database.");
                return;
            }
            PredefinedTag tag = new PredefinedTag();
            tag.setTag(addOntologyTagTextField.getText().trim());
            tag.setCategory((String) categoriesComboBox.getSelectedItem());
            addOntologyTagTextField.setText("");
            auxTagsList.add(tag);
            editedTagsModel.addElement(tag.getTag());
        }
}//GEN-LAST:event_addOntologyTagButtonActionPerformed

    private void addOntologyTagTextFieldKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_addOntologyTagTextFieldKeyReleased
        // TODO add your handling code here:
        String text = addOntologyTagTextField.getText();
        List tax = (List) taxonomies.get(categoriesComboBox
                .getSelectedIndex() - 1);
        Collections.sort(tax);
        ontologiesPopupMenu = new javax.swing.JPopupMenu();
        for (int i = 1; i < tax.size(); i++) {
            if (((String) tax.get(i)).toLowerCase().startsWith(
                    text.toLowerCase())) {
                final javax.swing.JMenuItem item =
                        new javax.swing.JMenuItem(
                        (String) tax.get(i));
                item.addActionListener(
                        new java.awt.event.ActionListener() {

                            @Override
                            public void actionPerformed(
                                    java.awt.event.ActionEvent e) {
                                addOntologyTagTextField.setText(
                                        item.getText());
                            }
                        });
                ontologiesPopupMenu.add(item);
            }
        }
        ontologiesPopupMenu.show(addOntologyTagTextField,
                addOntologyTagTextField.getX() - 5,
                addOntologyTagTextField.getY() + 10);
        addOntologyTagTextField.grabFocus();
}//GEN-LAST:event_addOntologyTagTextFieldKeyReleased

    private void categoriesComboBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_categoriesComboBoxItemStateChanged
        // TODO add your handling code here:
        if (categoriesComboBox.getSelectedIndex() > 0) {
            addOntologyTagTextField.setEnabled(true);
            addOntologyTagTextField.setText("");
        } else {
            addOntologyTagTextField.setEnabled(false);
            addOntologyTagTextField.setText("Choose a category");
        }
}//GEN-LAST:event_categoriesComboBoxItemStateChanged

    private void editedTagsListValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_editedTagsListValueChanged
        // TODO add your handling code here:
}//GEN-LAST:event_editedTagsListValueChanged

    private void editedTagsListFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_editedTagsListFocusLost
        // TODO add your handling code here:
}//GEN-LAST:event_editedTagsListFocusLost

    private void deleteTagButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteTagButtonActionPerformed
        // TODO add your handling code here:
        if (editedTagsList.getSelectedValue() != null) {
            auxTagsList.remove(editedTagsList.getSelectedIndex());
            editedTagsModel.removeElementAt(editedTagsList.getSelectedIndex());
        }
}//GEN-LAST:event_deleteTagButtonActionPerformed

    private void videoUrlBrowseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_videoUrlBrowseButtonActionPerformed
        // TODO add your handling code here:
        FileSystemView fsv = new FileChooser(
                new File(grupb.upf.util.Config.getProperty("video.folder"))
                .getAbsoluteFile());
        JFileChooser fc = new JFileChooser(fsv);
        FileFilter ff = new FileFilter() {

            @Override
            public boolean accept(final File f) {
                return true;
            }

            @Override
            public String getDescription() {
                return "Only video formats supported.";
            }
        };
        fc.setApproveButtonText("Select the url");
        fc.setApproveButtonToolTipText("Select or insert the name of the file");
        fc.setDialogTitle("Save the video");
        fc.setFileFilter(ff);
        fc.setCurrentDirectory(file.getParentFile());
        String path = file.getAbsolutePath();

        boolean isVideo = false;
        //format
        String extension = path.substring(path.lastIndexOf(".") + 1);
        for (int i = 0; i < VIDEO_FORMATS.length; i++) {
            if (VIDEO_FORMATS[i].equalsIgnoreCase(extension)) {
                isVideo = true;
            }
        }
        if (!isVideo) {
            path = path.substring(0, path.lastIndexOf(".") + 1) + "jpg";
        }
        fc.setSelectedFile(new File(path));
        if (fc.showOpenDialog(desktopPane) == JFileChooser.APPROVE_OPTION) {

            isVideo = false;
            //format
            extension =
                    fc.getSelectedFile().getAbsolutePath().substring(
                    fc.getSelectedFile().getAbsolutePath().lastIndexOf(".")
                    + 1);
            for (int i = 0; i < VIDEO_FORMATS.length; i++) {
                if (VIDEO_FORMATS[i].equalsIgnoreCase(extension)) {
                    isVideo = true;
                }
            }
            if (!isVideo) {
                p2piki.addError("Format not supported.");
            } else {
                urlTextField.setText(fc.getSelectedFile().getAbsolutePath());
            }
        }
}//GEN-LAST:event_videoUrlBrowseButtonActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        // TODO add your handling code here:
        if (grupb.upf.util.Config.getProperty("vlc.folder") == null) {
            p2piki.addError("You haven't configured correctly your VLC.");
        } else {
            final File f = new File(
                    grupb.upf.util.Config.getProperty("vlc.folder"));
            try {
                Process a = Runtime.getRuntime().exec("\"" +
                        f.getAbsolutePath() + "\\vlc\" \""
                        + file.getAbsolutePath() + "\"");
            }
            catch (Exception err) {
                if (LOG.isFatalEnabled()) {
                    LOG.fatal("Fatal error reproducing the video", err);
                    p2piki.addError("Error reproducing the video");
                }
            }
        }
    }//GEN-LAST:event_jButton1ActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton addOntologyTagButton;
    private javax.swing.JTextField addOntologyTagTextField;
    private javax.swing.JButton addPersonalTagButton;
    private javax.swing.JTabbedPane addTagTabbedPane1;
    private javax.swing.JTextField addTagTextField;
    private javax.swing.JComboBox categoriesComboBox;
    private javax.swing.JLabel categoryLabel1;
    private javax.swing.JTextField contributor;
    private javax.swing.JLabel contributorLabel;
    private javax.swing.JTextField creator;
    private javax.swing.JLabel creatorLabel;
    private javax.swing.JLabel dateView;
    private javax.swing.JButton deleteButton;
    private javax.swing.JInternalFrame deleteInternalFrame;
    private javax.swing.JButton deleteNoButton;
    private javax.swing.JButton deleteTagButton;
    private javax.swing.JButton deleteYesButton;
    private javax.swing.JTextArea description;
    private javax.swing.JLabel descriptionLabel;
    private javax.swing.JDesktopPane desktopPane;
    private javax.swing.JList editedTagsList;
    private javax.swing.JScrollPane editedTagsScrollPane1;
    private javax.swing.JPanel editionPanel;
    private javax.swing.JPanel editionPanelContainer;
    private javax.swing.JPanel generalPanel;
    private javax.swing.JPanel intellectualpanel;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JPopupMenu ontologiesPopupMenu;
    private javax.swing.JPanel ontologyTagPanel1;
    private javax.swing.JButton openVideoButton;
    private javax.swing.JButton openVideoButton1;
    private javax.swing.JPanel personalTagPanel1;
    private javax.swing.JTextField publisher;
    private javax.swing.JLabel publisherLabel;
    private javax.swing.JButton resetPropertiesButton;
    private javax.swing.JTextField rights;
    private javax.swing.JLabel rightsLabel;
    private javax.swing.JTextField source;
    private javax.swing.JLabel sourceLabel;
    private javax.swing.JTextField subject;
    private javax.swing.JLabel subjectLabel;
    private javax.swing.JTextField title;
    private javax.swing.JLabel titleLabel;
    private javax.swing.JLabel titleLabel1;
    private javax.swing.JLabel titleView;
    private javax.swing.JButton updatePropertiesButton;
    private javax.swing.JTextField urlTextField;
    private javax.swing.JButton videoUrlBrowseButton;
    // End of variables declaration//GEN-END:variables

}
